luci-base: form.js: rework stacked modal CBI map logic
authorJo-Philipp Wich <[email protected]>
Thu, 5 May 2022 21:07:13 +0000 (23:07 +0200)
committerJo-Philipp Wich <[email protected]>
Mon, 1 Aug 2022 09:57:42 +0000 (11:57 +0200)
Only stack a new modal CBI map on top of the currently displayed modal one
if the related map or section differs. This prevents misbehavior when
switching the protocol of interfaces.

Signed-off-by: Jo-Philipp Wich <[email protected]>
(cherry picked from commit f2fa59e89af3d4bdae9b12471184425b307ad5d6)

modules/luci-base/htdocs/luci-static/resources/form.js

index 6f6a423d5fc7b820a5b951024bf654c91652dfd1..98d934205766ad407c97c9845af1d23957952f1b 100644 (file)
@@ -3149,6 +3149,7 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
                    s = m.section(CBINamedSection, section_id, this.sectiontype);
 
                m.parent = parent;
+               m.section = section_id;
                m.readonly = parent.readonly;
 
                s.tabs = this.tabs;
@@ -3188,20 +3189,24 @@ var CBITableSection = CBITypedSection.extend(/** @lends LuCI.form.TableSection.p
                }
 
                return Promise.resolve(this.addModalOptions(s, section_id, ev)).then(L.bind(m.render, m)).then(L.bind(function(nodes) {
-                       var modalMap = this.getActiveModalMap();
+                       var mapNode = this.getActiveModalMap(),
+                           activeMap = mapNode ? dom.findClassInstance(mapNode) : null;
 
-                       if (modalMap) {
-                               modalMap.parentNode
+                       if (activeMap && (activeMap.parent !== parent || activeMap.section !== section_id)) {
+                               mapNode.parentNode
                                        .querySelector('h4')
                                        .appendChild(E('span', title ? ' ยป ' + title : ''));
 
-                               modalMap.parentNode
+                               mapNode.parentNode
                                        .querySelector('div.right > button')
                                        .firstChild.data = _('Back');
 
-                               modalMap.classList.add('hidden');
-                               modalMap.parentNode.insertBefore(nodes, modalMap.nextElementSibling);
-                               nodes.classList.add('flash');
+                               mapNode.classList.add('hidden');
+                               mapNode.parentNode.insertBefore(nodes, mapNode.nextElementSibling);
+
+                               return activeMap.save(null, true).then(function() {
+                                       nodes.classList.add('flash');
+                               }, function() {});
                        }
                        else {
                                ui.showModal(title, [